var ShopService = Backbone.Model.extend({
	datasource:null,
	initialize: function(args,options){
		_.extend(this , options);
	},
	loadAll:function(){
		this.url = this.datasource + "/shop/query";
		this.fetch({success:this.process_shops},{});
	},
	load:function(shopId){
		this.url = this.datasource + "/shop/query/" + shopId;
		this.fetch({success:this.process_shop},{});
	},
	process_shop: function(model, response) {
		var image = new Image();
		image.src = "data:image/png;base64," + response.floorplan ;
		var canvas = $("#trajectory #canvas").css("background-image","url(data:image/png;base64," + response.floorplan + ")")
		$(image).load(function(){
			canvas.attr({width : this.width,height:this.height});
		});
		
		
	},
	process_shops:function(model , response){
		var template = _.template($("#template-shops").html())({
            shops: response
        });
		$("#shop_selector").html(template);
		$("#shops").live("change",function(){
			_.extend(Settings,{datasource:$("#resources").val(),shop:this.value});
		});
	}
});